<template>
  <div class="tarbar">
    <div v-for="(item,index) in navList" 
    :key="item.path" 
    :class="[activeIndex === index ? 'active' : '']"
    @click="tarbarItemClick(item.path,index)">
      {{item.name}}
      <span v-if="activeIndex === index && activeIndex === 3" class="num">{{cartNum}}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'tarbar',
  props: {
    activeIndex: Number, // 当前选中的是第几个
    cartNum: [String,Number]      // 购物车中商品个数
  },
  data () {
    return {
      navList: [
        {
          path: '/home',
          name: '首页',
        },
        {
          path: '/category',
          name: '分类',
        },
        {
          path: '/find',
          name: '发现',
        },
        {
          path: '/cart',
          name: '购物车',
        },
        {
          path: '/personal',
          name: '我的',
        }
      ]
    }
  },
  methods: {
    tarbarItemClick(path,index){
      this.$router.push(path)
    }
  },
}
</script>

<style scoped lang="scss">
  .tarbar{
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: nowrap;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100px;
    background-color: #f9f9f9;
    div{
      height: 100%;
      line-height: 160px;
      width: 20%;
      color: #787878;
      font-size: 24px;
      background-position: center 10px;
      background-repeat: no-repeat;
      background-size: 50px 50px;
      position: relative;
      text-align: center;
      &:nth-of-type(1){
        background-image: url(../../../static/images/home.png);
      }
      &:nth-of-type(2){
        background-image: url(../../../static/images/category.png);
      }
      &:nth-of-type(3){
        background-image: url(../../../static/images/find.png);
      }
      &:nth-of-type(4){
        background-image: url(../../../static/images/shopcar.png);
      }
      &:nth-of-type(5){
        background-image: url(../../../static/images/me.png);
      }
      .num{
        position: absolute;
        top: 10px;
        right: 30px;
        min-width: 26px;
        height: 26px;
        border: 1px solid #fff;
        border-radius: 13px;
        color: #fff;
        line-height: 29px;
        text-align: center;
        background-color: #ca141d;
        font-size: 24px;
      }
    }
    .active{
      color: #ca141d;
      &:nth-of-type(1){
        background-image: url(../../../static/images/home_active.png);
      }
      &:nth-of-type(2){
        background-image: url(../../../static/images/category_active.png);
      }
      &:nth-of-type(3){
        background-image: url(../../../static/images/find_active.png);
      }
      &:nth-of-type(4){
        background-image: url(../../../static/images/shopcar_active.png);
      }
      &:nth-of-type(5){
        background-image: url(../../../static/images/me_active.png);
      }
    }
  }
</style>
